package com.han.hotelplat.service.hotelroom.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.han.hotelplat.dao.hotelroom.HotelRoomDao;
import com.han.hotelplat.pojo.hotelroom.HotelRoom;
import com.han.hotelplat.service.hotelroom.HotelRoomService;

@Service
public class HotelRoomServiceImpl implements HotelRoomService{
	@Autowired
	private HotelRoomDao hotelRoomDao;
	
	@Override
	public HotelRoom getHoteRoomById(Integer id) {
		return hotelRoomDao.findById(id);
	}

	@Override
	public void updateHotelRoom(HotelRoom hr) {
		hotelRoomDao.update(hr);
	}

	@Override
	public void deleteHotelRoom(Integer hotelId) {
		hotelRoomDao.deleteByProperty("hotelid", hotelId);
	}

	@Override
	public void saveHotelRoom(HotelRoom hr) {
		hotelRoomDao.save(hr);
	}

	@Override
	public List<HotelRoom> findHotelRoomByHotelId(Integer id) {
		String hql ="from HotelRoom where hotelid="+id;
		return hotelRoomDao.findByHQL(hql);
	}

	@Override
	public HotelRoom getCriterionRoom(Integer hotelId) {
		List<HotelRoom> re = findHotelRoomByHotelId(hotelId);
		for(HotelRoom r : re){
			if(r.getName().equals("标间")){
				return r;
			}
		}
		return null;
	}
	
}
